<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;
use Think\Exception;

class InsuranceController extends AdminbaseController{
    
	protected $insuranceCompanyModel;
	
	public function _initialize() {
		parent::_initialize();
		$this->insuranceCompanyModel = D("InsuranceCompany");
	}

	//保险公司列表
	public function index(){
		$insuranceCompanies=$this->insuranceCompanyModel->select();
        $this->assign('insuranceCompanies',$insuranceCompanies);
        $this->display();
	}

	// 保险公司添加
	public function add(){
		$this->display();
	}
	
	// 保险公司添加提交
	public function add_post(){
		if(IS_POST){
			if ($this->insuranceCompanyModel->create()!==false){
				if ($this->insuranceCompanyModel->add()!==false) {
					$this->success('添加成功', U("Insurance/index"));
				} else {
					$this->error('添加失败');
				}
			} else {
				$this->error($this->insuranceCompanyModel->getError());
			}
		
		}
	}
	
	// 保险公司编辑
	public function edit(){
		$id=I("get.id",0,'intval');
		$insuranceCompany=$this->insuranceCompanyModel->where(array('id'=>$id))->find();
		$this->assign(['insuranceCompany'=>$insuranceCompany]);
		$this->display();
	}
	
	// 保险公司编辑提交
	public function edit_post(){
		if (IS_POST) {
			if ($this->insuranceCompanyModel->create()!==false) {
				if ($this->insuranceCompanyModel->save()!==false) {
					$this->success("保存成功！", U("Insurance/index"));
				} else {
					$this->error("保存失败！");
				}
			} else {
				$this->error($this->insuranceCompanyModel->getError());
			}
		}
	}
	
	// 保险公司删除
	public function delete(){
		$id = I("get.id",0,"intval");
		if ($this->insuranceCompanyModel->delete($id)!==false) {
			$this->success("删除成功！");
		} else {
			$this->error("删除失败！");
		}
	}
	
}